﻿namespace System.Web
{
    public partial class NetHttpApplication : IDisposable
    {
        private void InitAppLevelCulture()
        {
            //GlobalizationSection globalization = RuntimeConfig.GetAppConfig().Globalization;
            //string culture = globalization.Culture;
            //string uICulture = globalization.UICulture;
            //if (!string.IsNullOrEmpty(culture))
            //{
            //    if (StringUtil.StringStartsWithIgnoreCase(culture, AutoCulture))
            //    {
            //        _appLevelAutoCulture = true;
            //        if (GetFallbackCulture(culture) != null)
            //            _appLevelCulture = HttpServerUtility.CreateReadOnlyCultureInfo(culture.Substring(5));
            //    }
            //    else
            //    {
            //        _appLevelAutoCulture = false;
            //        _appLevelCulture = HttpServerUtility.CreateReadOnlyCultureInfo(globalization.Culture);
            //    }
            //}
            //if (!string.IsNullOrEmpty(uICulture))
            //{
            //    if (StringUtil.StringStartsWithIgnoreCase(uICulture, AutoCulture))
            //    {
            //        _appLevelAutoUICulture = true;
            //        if (GetFallbackCulture(uICulture) != null)
            //        {
            //            _appLevelUICulture = HttpServerUtility.CreateReadOnlyCultureInfo(uICulture.Substring(5));
            //        }
            //    }
            //    else
            //    {
            //        _appLevelAutoUICulture = false;
            //        _appLevelUICulture = HttpServerUtility.CreateReadOnlyCultureInfo(globalization.UICulture);
            //    }
            //}
        }

        private void RestoreAppLevelCulture()
        {
            //CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
            //CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
            //if (_savedAppLevelCulture != null)
            //{
            //    if (currentCulture != _savedAppLevelCulture)
            //    {
            //        HttpRuntime.SetCurrentThreadCultureWithAssert(_savedAppLevelCulture);
            //    }
            //    _savedAppLevelCulture = null;
            //}
            //if (_savedAppLevelUICulture != null)
            //{
            //    if (currentUICulture != _savedAppLevelUICulture)
            //    {
            //        Thread.CurrentThread.CurrentUICulture = _savedAppLevelUICulture;
            //    }
            //    _savedAppLevelUICulture = null;
            //}
        }

        private void SetAppLevelCulture()
        {
            //CultureInfo cultureInfo = null;
            //CultureInfo info2 = null;
            //CultureInfo info3 = null;
            //string name = null;
            //if ((_appLevelAutoCulture || _appLevelAutoUICulture) && ((_context != null) && !_context.HideRequestResponse))
            //{
            //    name = _context.UserLanguageFromContext();
            //    if (name != null)
            //    {
            //        try
            //        {
            //            info3 = HttpServerUtility.CreateReadOnlySpecificCultureInfo(name);
            //        }
            //        catch
            //        {
            //        }
            //    }
            //}
            //cultureInfo = _appLevelCulture;
            //info2 = _appLevelUICulture;
            //if (info3 != null)
            //{
            //    if (_appLevelAutoCulture)
            //    {
            //        cultureInfo = info3;
            //    }
            //    if (_appLevelAutoUICulture)
            //    {
            //        info2 = info3;
            //    }
            //}
            //_savedAppLevelCulture = Thread.CurrentThread.CurrentCulture;
            //_savedAppLevelUICulture = Thread.CurrentThread.CurrentUICulture;
            //if ((cultureInfo != null) && (cultureInfo != Thread.CurrentThread.CurrentCulture))
            //{
            //    HttpRuntime.SetCurrentThreadCultureWithAssert(cultureInfo);
            //}
            //if ((info2 != null) && (info2 != Thread.CurrentThread.CurrentUICulture))
            //{
            //    Thread.CurrentThread.CurrentUICulture = info2;
            //}
        }
    }
}
